package panel.home.fastBtn
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	
	import main.ClientConstants;
	
	public class FastBtnGroup extends Sprite
	{
		private var _stage:Stage;
		private var _locationBtn:LocationFastBtn;
		private  var _weatherBtn:WeatherFastBtn;
		private var _helpBtn:HelpFastBtn;
		private var _moreBtn:MoreFastBtn;
		private var _myPathBtn:MyPathFastBtn;
		private var _suntimeBtn:SuntimeFastBtn;
		
		private var _nagivationFunc:Function;
		private var _weatherFunc:Function;
		private var _moreFunc:Function;
		private var _helpFunc:Function;
		private var _myPathFunc:Function;
		private var _suntimeFunc:Function;
		
		public function FastBtnGroup(stage:Stage)
		{
			_stage = stage;
			super();
		}
		
		public function init(...args):void
		{
			_nagivationFunc = args[0];
			_weatherFunc = args[1];
			_helpFunc = args[2];
			_myPathFunc = args[3]
			_moreFunc = args[4];
			_suntimeFunc = args[5];
			_locationBtn = new LocationFastBtn();
			_weatherBtn = new WeatherFastBtn();
			_helpBtn = new HelpFastBtn();
			_myPathBtn = new MyPathFastBtn();
			_moreBtn = new MoreFastBtn();
			_suntimeBtn = new SuntimeFastBtn();
			var btnList:Array = [_locationBtn,_weatherBtn,_helpBtn,_myPathBtn,_suntimeBtn,_moreBtn];
			
			btnList[0].x = 0;
			this.addChild(btnList[0]);
			var distanceX:Number = (_stage.stageWidth / 3 - btnList[0].width);
			var distanceY:Number = btnList[0].height / 6;
			
			btnList[1].x = btnList[0].x + btnList[0].width +  distanceX;
			this.addChild(btnList[1]);
			
			btnList[2].x = btnList[1].x + btnList[1].width +  distanceX;
			this.addChild(btnList[2]);
			
			btnList[3].x = 0;
			btnList[3].y = btnList[0].y + btnList[0].height + distanceY;
			this.addChild(btnList[3]);
			
			btnList[4].x = btnList[1].x + (btnList[1].width - btnList[4].width) * 0.5;
			btnList[4].y = btnList[3].y;
			this.addChild(btnList[4]);
			
			
			btnList[5].x = btnList[2].x;
			btnList[5].y = btnList[3].y;
			this.addChild(btnList[5]);
			
			this.y = _stage.stageHeight * ClientConstants.HOME_UP_PER + _stage.stageHeight / 30;
			this.x = (_stage.stageWidth - (btnList[2].x + btnList[2].width)) /2
			
			_locationBtn.addEventListener(MouseEvent.CLICK,nagivationHandler);
			_weatherBtn.addEventListener(MouseEvent.CLICK,weatherHandler);
			_helpBtn.addEventListener(MouseEvent.CLICK,helpHandler);
			_moreBtn.addEventListener(MouseEvent.CLICK,moreHandler);
			_myPathBtn.addEventListener(MouseEvent.CLICK,myPathHandler);
			_suntimeBtn.addEventListener(MouseEvent.CLICK,clickSuntimeHandler);
		}
		
		protected function clickSuntimeHandler(event:MouseEvent):void
		{
			_suntimeFunc();
		}
		
		protected function myPathHandler(event:MouseEvent):void
		{
			if(_myPathFunc is Function){
				_myPathFunc();
			}
		}
		
		protected function moreHandler(event:MouseEvent):void
		{
			_moreFunc();
		}
		
		protected function helpHandler(event:MouseEvent):void
		{
			_helpFunc();
		}
		
		protected function weatherHandler(event:MouseEvent):void
		{
			_weatherFunc();
		}
		
		protected function nagivationHandler(event:MouseEvent):void
		{
			_nagivationFunc();
		}
		
		public function clear():void
		{
			_locationBtn.removeEventListener(MouseEvent.CLICK,nagivationHandler);
			_weatherBtn.removeEventListener(MouseEvent.CLICK,weatherHandler);
			_helpBtn.removeEventListener(MouseEvent.CLICK,helpHandler);
			_moreBtn.removeEventListener(MouseEvent.CLICK,moreHandler);
			_myPathBtn.removeEventListener(MouseEvent.CLICK,myPathHandler);
			_suntimeBtn.removeEventListener(MouseEvent.CLICK,clickSuntimeHandler);
			
			_locationBtn.clear();
			_weatherBtn.clear();
			_helpBtn.clear();
			_myPathBtn.clear();
			_moreBtn.clear();
			
			_locationBtn = null;
			_weatherBtn = null;
			_helpBtn = null;
			_myPathBtn = null;
			_moreBtn = null;
		}
	}
}